from apps.contents.models import ContentCategory
from utils.goods import get_categories
import time

def generate_static_index_html():
    print('------%s------'%time.ctime())
    categories = get_categories()
    contents = {}
    content_categories = ContentCategory.objects.all()
    for cat in content_categories:
        contents[cat.key] = cat.content_set.filter(status=True).order_by('sequence')

    context = {
        'categories': categories,
        'contents': contents,
    }
    from django.template import loader
    indx_template = loader.get_template('index.html')
    index_html = indx_template.render(context)

    from meiduo_mall import settings
    import os
    file_path = os.path.join(os.path.dirname(settings.BASE_DIR),'front_end_pc/index.html')
    with open(file_path,'w',encoding='utf-8') as f:
        f.write(index_html)